package com.itheima.homework.work9;

import java.util.Random;
import java.util.Scanner;

public class Demo9 {
    public static void main(String[] args) {
        String str = new String();
        for (char da = 'A', xiao = 'a'; da <= 'Z' && xiao <= 'z'; da++, xiao++) {
            str += da;
            str += xiao;
        }
        str += "0123456789";
        //System.out.println(str);

        Scanner scanner = new Scanner(System.in);
        for (int i = 1; i <= 3; i++) {
            String str1 = "";
            for (int j = 0; j < 4; j++) {
                Random r = new Random();
                int k = r.nextInt(str.length());
                char c = str.charAt(k);///
                str1 += c;
            }
            System.out.println("生成的验证码为："+str1);
            System.out.println("请输入验证码:");
            String string = scanner.nextLine();
            if (string.equalsIgnoreCase(str1)) {
                System.out.println("验证码正确");
                break;
            } else {
                if (i==3){
                    System.out.println("3次机会已用完");
                }else{

                    System.out.println("输入错误，请重新输入剩于"+(3-i)+"次机会");
                }
            }
        }
    }
}
